package linkedlist;

/**
 * @author 十八岁讨厌编程
 * @date 2025/6/27 21:07
 * @PROJECT_NAME leetcode
 * @description
 */

public class Solution203 {



    public ListNode removeElements(ListNode head, int val) {
        ListNode virtualHead = new ListNode(-1,head);
        ListNode pointer = virtualHead;
        while(pointer != null && pointer.next != null) {
            if(pointer.next.val == val) {
                pointer.next = pointer.next.next;
                continue;
            }
            pointer = pointer.next;
        }
        return virtualHead.next;
    }

}
